package com.act.web;

import com.act.domain.CustomsManagement;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.ICustomsManagementService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("cm")
public class CustomesManagementController {

    @Resource
    private  ICustomsManagementService customsManagementService;
    
	private final Logger LOGGER = Logger.getLogger(CustomesManagementController.class);	

    @RequestMapping(value="/get/{type}/{payee}",method=RequestMethod.POST)
    @ResponseBody
    public Response  getAllByTypeOrPayyee(@PathVariable String type,@PathVariable String payee,@RequestBody PagerDTO pagerDTO){
    			try {
    				PagerVo<Map> pagerVo = customsManagementService.getAllByTypeOrPayyee(type, payee, pagerDTO);

    				return Response.success(pagerVo);
    			} catch (Exception e) {
    				LoggerUtil.error(LOGGER, e);
    			}
    			return Response.fail();
    }

    @RequestMapping(value="/getById/{id}",method=RequestMethod.GET)
    @ResponseBody
    public Response  getById(@PathVariable int id){
			try {
				CustomsManagement c= customsManagementService.getCustomsById(id);

				return Response.success(c);
			} catch (Exception e) {
				LoggerUtil.error(LOGGER, e);
			}
			return Response.fail();
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(@RequestBody CustomsManagement customsManagement) {
        try {
            customsManagementService.add(customsManagement);
            return Response.success();
        } catch (Exception e) {

            return Response.fail();
        }
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody

    public Response delete(@RequestBody int id){
        try {
            customsManagementService.delete(id);
            return Response.success();
        } catch (Exception e) {

            return Response.fail();
        }

    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(@RequestBody CustomsManagement customsManagement) {
        try {
            customsManagementService.update(customsManagement);
            return Response.success();
        } catch (Exception e) {

            return Response.fail();
        }
    }
    
    @RequestMapping(value = "/get",method = RequestMethod.POST)
    @ResponseBody
    public Response getAll(@RequestBody PagerDTO pagerDTO) {
        try {
            PagerVo<Map> pagerVo = customsManagementService.getAll(pagerDTO);
            return Response.success(pagerVo);
        } catch (Exception e) {
            return Response.fail();
        }
    }
}
